package com.ruoyi.biz.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.biz.domain.BizTopicFollow;
import com.ruoyi.biz.mapper.BizTopicFollowMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;


/**
 * 跟进详情Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-19
 */
@Service
public class BizTopicFollowService extends ServiceImpl<BizTopicFollowMapper, BizTopicFollow> {

    /**
     * 查询子课题列表
     */
    public List<BizTopicFollow> list(BizTopicFollow req) {
        return baseMapper.list(req);
    }

    /**
     * 根据ID查询
     */
    public BizTopicFollow selectById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 新增修改子课题
     */
    @Transactional(rollbackFor = Exception.class)
    public void beforeSave(BizTopicFollow bizTopic) {
        if (bizTopic.getId() != null) {
            bizTopic.setUpdateTime(DateUtils.getNowDate());
        } else {
            bizTopic.setCreateTime(DateUtils.getNowDate());
            bizTopic.setUpdateTime(DateUtils.getNowDate());
            bizTopic.setUserId(getUserId());
        }
        saveOrUpdate(bizTopic);
    }

    /**
     * 批量删除子课题
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
